<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>登录</title>
    <meta name="keywords" content="{$_G[keywords]}">
    <meta name="description" content="{$_G[description]}">
    <link rel="icon" href="/static/images/common/favicon.png">
    <link rel="stylesheet" type="text/css" href="/static/css/account.css">
    <script src="/static/js/jquery.js" type="text/javascript"></script>
    <script src="/static/js/common.js" type="text/javascript"></script>
    <script src="/static/js/jquery.form.js" type="text/javascript"></script>
    <script src="/static/js/jquery.dsxui.js" type="text/javascript"></script>
</head>
<body>
<div class="area main-body-div">
    <div class="sign-in-map"></div>
    <div class="sign-in-div">
        <div class="content" id="loginView">
            <h3>快速登录</h3>
            <div class="sign-content">
                <form method="post" id="loginForm" autocomplete="off">
                    <input type="hidden" id="J_refer" name="refer" value="{$redirect}">
                    <input type="hidden" name="formhash" value="{FORMHASH}">
                    <div class="err-tips" id="err-tips"></div>
                    <div class="input-div">
                        <div class="ico-box"><i class="iconfont icon-my"></i></div>
                        <div class="input-box"><input type="text" class="text" id="account" name="account_{FORMHASH}" placeholder="用户名/手机号/邮箱"></div>
                    </div>
                    <div class="input-div">
                        <div class="ico-box"><i class="iconfont icon-lock"></i></div>
                        <div class="input-box"><input type="password" class="text" id="password" name="password_{FORMHASH}" placeholder="密码" maxlength="20"></div>
                    </div>
                    <div class="input-div">
                        <div class="ico-box"><i class="iconfont icon-attention_light"></i></div>
                        <div class="input-box">
                            <input type="text" name="captchacode" class="text" id="captchacode" placeholder="验证码" maxlength="4">
                            <img src="/index.php?m=plugin&c=captcha" onclick="this.src='/index.php?m=plugin&c=captcha&'+Math.random()" title="看不清，换一张" class="captcha">
                        </div>
                    </div>
                    <div class="sign-button-div"><button type="submit" id="btnlogin" class="sign-button">登录</button></div>
                    <div class="sign-link">
                        <span><a href="">忘记密码?</a></span>
                        <a href="/?m=account&c=register">新用户注册</a>
                    </div>
                </form>
            </div>
            <div class="saoma-login" id="saoma-login"></div>
        </div>

        <div class="content" id="saomaView" style="display: none;">
            <h3>手机扫码，安全登录</h3>
            <div class="scan-login">
                <img id="qrcode" class="qrcode">
                <div class="qrcode-desc">打开手机APP 扫一扫登录</div>
            </div>
            <div class="diannao-login" id="diannao-login"></div>
            <div class="loading" id="loading"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var timer = null;
    function scanQuery() {
        $.ajax({
            dataType:'json',
            url:"{U:('m=account&c=login&a=scan_query')}",
            success:function (response) {
                if (response.errcode == 0){
                    confirmLogin();
                }else {
                    timer = setTimeout(function () {
                        scanQuery();
                    }, 1000);
                }
            }
        });
    }
    function confirmLogin() {
        $.ajax({
            dataType:'json',
            url:"{U:('m=account&c=login&a=confirm_login')}",
            beforeSend:function () {
                $("#loading").show();
            },
            success:function (response) {
                if (response.errcode == 0){
                    $("#loading").hide();
                    setTimeout(function () {
                        if ($("#J_refer").val()){
                            window.location.href = $("#J_refer").val();
                        }else {
                            DSXUtil.reFresh();
                        }
                    }, 1000);
                }else {
                    DSXUI.error(response.errmsg);
                }
            }
        });
    }
    $(function () {
        function checkLogin() {
            var account = $("#account").val();
            if(!DSXValidate.IsUserName(account) && !DSXValidate.IsMobile(account) && !DSXValidate.IsEmail(account)){
                $("#err-tips").text('账号输入错误').show();
                return false;
            }
            var password = $("#password").val();
            if(!DSXValidate.IsPassword(password)){
                $("#err-tips").text('密码错误').show();
                return false;
            }
            var captcha = $("#captchacode").val();
            if(captcha.length != 4){
                $("#err-tips").text('验证码错误').show();
                return false;
            }
            $.ajax({
                type:'POST',
                url:"{U:('m=account&c=login&a=chklogin&inajax=1')}",
                async:false,
                dataType:"json",
                data:$("#loginForm").serializeArray(),
                success: function(json){
                    if(json.errcode == 0){
                        if ($("#J_refer").val()){
                            window.location.href = $("#J_refer").val();
                        }else {
                            DSXUtil.reFresh();
                        }
                    }else {
                        $(".captcha").attr('src','/index.php?m=plugin&c=captcha&'+Math.random());
                        $("#err-tips").text(json.errmsg).show();
                    }
                }
            });
            return false;
        }
        $("#saoma-login").on('click', function () {
            $("#loginView").hide();
            $("#saomaView").show();
            $("#qrcode").attr("src","{U:('m=account&c=login&a=qrcode')}");
            scanQuery();
        });
        $("#diannao-login").on('click', function () {
            $("#loginView").show();
            $("#saomaView").hide();
            clearTimeout(timer);
        });
        $("#loginForm").on('submit', checkLogin);
    });
</script>
<div class="footer" id="footer">
    <div class="area">
        <div class="bottomNav">
            <a href="/">网站首页</a>
            <span class="split">|</span>
            <a href="#">关于我们</a>
            <span class="split">|</span>
            <a href="#">联系方式</a>
            <span class="split">|</span>
            <a href="#">广告服务</a>
            <span class="split">|</span>
            <a href="#">法律援助</a>
            <span class="split">|</span>
            <a href="#">加入我们</a>
            <span class="split">|</span>
            <a href="#">支付方式</a>
            <span class="split">|</span>
            <a href="#">技术支持</a>
        </div>
        <div class="copyright">©2016 郎客你好版权所有   闽ICP备17008804号</div>
    </div>
</div>
</body>
</html>